<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true"
    CodeFile="ExportCM.aspx.cs" Inherits="ExportCM" Title="ExportCM" %>

<%@ MasterType VirtualPath="~/MasterPage.master" %>
<%@ Register Namespace="NS_Controls" TagPrefix="cc1" %>
<%@ Register Namespace="CustomControlsNS" TagPrefix="cc2" %>
<asp:Content ID="ContentDefault" ContentPlaceHolderID="ContentPlaceHolderContent"
    runat="Server">
    <link href="../../Styles/themes/fancy/tabs.css" rel="stylesheet" type="text/css" />
    <link href="../../Styles/themes/fancy/fancy-blue/fancy-blue.css" rel="stylesheet"
        type="text/css" />
    <asp:UpdatePanel ID="upExportCM" runat="server">
        <ContentTemplate>
            <div style="padding-bottom: 20px">
                <ajaxToolKit:TabContainer ID="tabContainer" runat="server" CssClass="fancy fancy-blue"
                    AutoPostBack="true">
                    <ajaxToolKit:TabPanel ID="tabExportCM" runat="server" HeaderText="Export Concedii Medicale">
                        <ContentTemplate>
                            <div id="divTitluPagina" runat="server" style="height: 100%; overflow: auto; display: block">
                                <table id="tblTitlu" runat="server" width="98%">
                                    <tr>
                                        <td>
                                            <div class="menu_th">
                                                <table>
                                                    <tr>
                                                        <td>
                                                            <asp:Label ID="lblExpCM" runat="server" CssClass="menu_th1">Export Concedii Medicale</asp:Label>
                                                        </td>
                                                        <td>
                                                            <asp:UpdateProgress ID="UpdateProgressExpCM" runat="server" DisplayAfter="100">
                                                                <ProgressTemplate>
                                                                    <span id="spnProgress" class="clsTextBoldYellow">(<% =Resources.GridView.PageLoading %>)</span>
                                                                </ProgressTemplate>
                                                            </asp:UpdateProgress>
                                                        </td>
                                                    </tr>
                                                </table>
                                            </div>
                                        </td>
                                    </tr>
                                </table>
                            </div>
                            <table width="98%">
                                <tr class="tdn">
                                    <td style="width: 15%" align="right">
                                        <asp:Literal ID="startDate" runat="server" Text="<%$ Resources:DatabaseStrings, StartDate%>" />
                                        :&nbsp;
                                    </td>
                                    <td style="width: 35%">
                                        <span class="tdSmall">
                                            <asp:TextBox ID="txtDataStart" runat="server" MaxLength="10" />
                                            <asp:ImageButton ID="imgDataStart" runat="server" ImageUrl="~/images/Calendar_scheduleHS.png"
                                                BorderWidth="0" Width="16" Height="16" Style="position: relative; top: 0; left: 0;" />
                                            <ajaxToolKit:FilteredTextBoxExtender ID="FilteredTextBoxExtenderStart" runat="server"
                                                TargetControlID="txtDataStart" ValidChars=".-/0123456789" />
                                            <ajaxToolKit:CalendarExtender ID="calDataStart" runat="server" TargetControlID="txtDataStart"
                                                PopupButtonID="imgDataStart" Format="dd/MM/yyyy" />
                                            <ajaxToolKit:CalendarExtender ID="calDataStart2" runat="server" TargetControlID="txtDataStart"
                                                Format="dd/MM/yyyy" />
                                        </span>
                                    </td>
                                    <td style="width: 15%" align="right">
                                        <asp:Literal ID="endDate" runat="server" Text="<%$ Resources:DatabaseStrings, EndDate%>" />
                                        :&nbsp;
                                    </td>
                                    <td style="width: 35%">
                                        <span class="tdSmall">
                                            <asp:TextBox ID="txtDataEnd" runat="server" MaxLength="10" />
                                            <asp:ImageButton ID="imgDataEnd" runat="server" ImageUrl="~/images/Calendar_scheduleHS.png"
                                                BorderWidth="0" Width="16" Height="16" Style="position: relative; top: 0; left: 0;" />
                                            <ajaxToolKit:FilteredTextBoxExtender ID="FilteredTextBoxExtenderEnd" runat="server"
                                                TargetControlID="txtDataEnd" ValidChars=".-/0123456789" />
                                            <ajaxToolKit:CalendarExtender ID="calDataEnd" runat="server" TargetControlID="txtDataEnd"
                                                PopupButtonID="imgDataEnd" Format="dd/MM/yyyy" />
                                            <ajaxToolKit:CalendarExtender ID="calDataEnd2" runat="server" TargetControlID="txtDataEnd"
                                                Format="dd/MM/yyyy" />
                                        </span>
                                    </td>
                                </tr>
                                <tr class="tdn">
                                    <td colspan="4">
                                        <cc2:CustomButton ID="btnSave" runat="server" Text="Importa DBF" OnServerClick="btnSave_Click"
                                            OnClick="StartTheTimer();" />
                                        <cc2:CustomButton ID="btnClear" runat="server" Text="Goleste DBF" OnServerClick="btnClear_Click" />
                                        <cc2:CustomButton ID="btnDownload" runat="server" Text="Descarca DBF" OnServerClick="btnDownload_Click" />
                                    </td>
                                </tr>
                            </table>
                            <div id="divMessageBox" class="greenFont" style="border: 5px; border-color: Red;
                                height: 50px; width: 98%; background-color: #C2DFFF;">
                                <asp:Literal ID="mesajStatus" runat="server" />
                                <span id="spanTimer" style="height: 50px"></span>
                            </div>
                            <asp:Literal ID="output" runat="server" />
                        </ContentTemplate>
                    </ajaxToolKit:TabPanel>
                </ajaxToolKit:TabContainer>
                <div id="divLinkHome" style="padding: 10px">
                    <asp:Image runat="Server" ID="imgReturnMain" ImageUrl="~/Images/Hipocrate/icon_home.gif"
                        AlternateText="Click to return" UseSubmitBehavior="false" Style="cursor: pointer" />
                    <asp:HyperLink ID="lnkMainPage" runat="server" Text="Inapoi la pagina principala"
                        NavigateUrl="~/Default.aspx" />
                </div>
            </div>
        </ContentTemplate>
    </asp:UpdatePanel>
    <script language="javascript" type="text/javascript">
        var g_str_div = 'spanPageMethod';
        var g_str_spanTrace = 'spanTrace';

        var delayTimer = 1000;
        var timer = null;
        var timeStr = null;

        function hideModal() {
            StopTheTimer();
            if (timeStr != null)
                $get('spanTimer').innerHTML = '<br/><img src="../../Images/Hipocrate/check.gif" />' +
					'Exportul s-a realizat in:   ' + timeStr;
            else
            //$get('spanTimer').innerHTML = '<br/><img src="../../Images/Hipocrate/del.gif" />' +
            //'Exportul nu s-a realizat!';
                $get('spanTimer').innerHTML = '<br/><img src="../../Images/Hipocrate/check.gif" />' +
                    'Exportul s-a realizat in: 0:00';
					
        }

        var startUpTime;
        function StartTheTimer() {
            startUpTime = new Date();
            timer = window.setInterval("getTime()", delayTimer);
        }

        function StartThreadTimer() {
            $get(g_str_div).innerHTML = '[start]';
            startUpTime = new Date();
            timer = window.setInterval("getTime()", delayTimer);
            $get('stopTimer').style.visibility = 'visible';
        }

        function StopTheTimer() {
            clearTimeout(timer);
            if ($get('stopTimer') != null)
                $get('stopTimer').style.visibility = 'hidden';
        }

        function getTime() {
            var time = new Date();
            var diff = ((24 + time.getHours() - startUpTime.getHours()) % 24) * 3600 + time.getMinutes() * 60 + time.getSeconds() - startUpTime.getMinutes() * 60 - startUpTime.getSeconds();
            var curr_sec = diff % 60;
            var curr_min = (diff - curr_sec) / 60;
            timeStr = curr_min + " : " + (curr_sec < 10 ? '0' : '') + curr_sec + ' ';
            $get('spanTimer').innerHTML = "<br />&nbsp;&nbsp;&nbsp;" + timeStr;
            if ($get('spanMessage') == null) return;
            var existingText = $get('spanMessage').innerHTML;
            if (existingText == '')
                existingText = '...';
            //$get('spanMessage').innerHTML = '(' + existingText + ')';
            $get('spanMessage').innerHTML = existingText + '*';
            //messageStatus('');
        }

        var stillWaiting = false;
        function messageStatus(message) {
            if (stillWaiting) {
                $get(g_str_div).innerHTML += " [...] ";
                return;
            }
            stillWaiting = true;
            PageMethods.getStatus(onGetdataSuccess, onGetdataFail);
            $get(g_str_div).innerHTML += " [*] Fetching status...";
            xmlhttp = new XMLHttpRequest();
            xmlhttp.open("GET", "ExportDRG.aspx?getStatus=myId", true);
            xmlhttp.onreadystatechange = function () {
                $get(g_str_div).innerHTML += ' [' + xmlhttp.readyState + '] ' + xmlhttp.status;
                if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                    $get(g_str_div).innerHTML += ' -- ' + xmlhttp.responseText;
                    stillWaiting = false;
                }
            }
            xmlhttp.send();
        }

        function onGetdataSuccess(response) {
            $get('spanMessage').innerHTML = response;
            var div = $get(g_str_div);
            div.innerHTML += response + "<br/>";
            div.scrollTop = 99999;
        }
        function onGetdataFail() {
            $get('spanMessage').innerHTML = '-';
        }

        function testPage(x) {
            $get(g_str_div).innerHTML += '<br/>' + x;
        }
    </script>
</asp:Content>
